<template>
  <div id="app">
    <a-input placeholder="请输入任务"  :value='inputvalue'  class="my_ipt" @change="handele" />
    <a-button type="primary" @click="addinfo">添加事项</a-button>

    <a-list bordered :dataSource="list" class="dt_list">
      <a-list-item slot="renderItem" slot-scope="item">
        <!-- 复选框 -->
        <a-checkbox @change="changgered(item.id)" >{{item.info}}</a-checkbox>
        <!-- 删除链接 -->
        <a slot="actions" @click="remove(item.id)">删除</a>
      </a-list-item>

      <!-- footer区域 -->
      <div slot="footer" class="footer">
        <!-- 未完成的任务个数 -->
        <span>{{leftNuber}}条剩余</span>
        <!-- 操作按钮 -->
        <a-button-group>
          <a-button :type="select===1?'primary': '' "  @click="djchangge(1)" >全部</a-button>
          <a-button :type="select===2?'primary': '' " @click="djchangge(2)">未完成</a-button>
          <a-button :type="select===3?'primary': '' "  @click="djchangge(3)">已完成</a-button>
        </a-button-group>
        <!-- 把已经完成的任务清空 -->
        <a @click="clearlist">清除已完成</a>
      </div>
    </a-list>
  </div>
</template>

<script>
import { mapState, mapMutations, mapGetters } from 'vuex'
export default {
  name: 'app',
  data () {
    return {

    }
  },
  created () {
    this.$store.dispatch('getlist')
  },
  computed: {
    ...mapState(['list', 'inputvalue', 'select']),
    ...mapGetters(['leftNuber', 'slectliste'])
  },
  methods: {
    ...mapMutations(['setinputvalue', 'additem', 'remove', 'changgered', 'djchangge', 'clearlist']),

    handele (e) {
      // this.$store.commit('setinputvalue', e.target.value)
      this.setinputvalue(e.target.value.trim())
    },
    addinfo () {
      if (this.inputvalue.trim().length <= 0) {
        return this.$message.warring('不能输入为空')
      } else {
        this.additem()
      }
    }

  }

}
</script>

<style scoped>
#app {
  padding: 10px;
}

.my_ipt {
  width: 500px;
  margin-right: 10px;
}

.dt_list {
  width: 500px;
  margin-top: 10px;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
